<?php
/**
 * 会员中心
 * User: chen guang
 * Date: 2017/9/29 9:00
 *
 */

namespace app\websys\Controller;
use think\Db;

class Member extends Common{
	
	/*
	*	构造函数
	*/
	function __construct(){
		parent::__construct();

	}

    /**
     * 会员列表
     */
    public function lists(){
		$where['delete']=1;
		$status=input("status");
		if($status!=''){
			$where['status']=$status;
		}
		$type=input("type");
		if($type!=''){
			$where['type']=$type;
		}
		if(input("keyword")){
			$where['nickname|mobile']=array("like",'%'.input('keyword').'%');
		}
        $list = db("member")->where($where)->order("id desc")->paginate(6);
        $this->assign('list',$list);
		$this->assign('status',input("status"));
		$this->assign('type',input("type"));
		$this->assign('keyword',input("keyword"));
        return $this->fetch();
    }
	/*
  * 设置黑名单
  */
	public function setblack(){
		$id = input('id/d');
		if(!in_array(input('status'),array(0,1))){
			$this->error("状态有误");
		}
		$data['status'] = input('status');
		$res=db("member")->where("id='$id'")->update($data);
		if($res) $this->redirect($_SERVER['HTTP_REFERER']);
		$this->error("操作失败");
	}
	
	/*
  * 变会员等级
  */
	public function grade(){
		$id = input('id/d');
		if(!in_array(input('status'),array(1,2,3,4))){
			$this->error("状态有误");
		}
		$data['type'] = input('status');
		$res=db("member")->where("id='$id'")->update($data);
		if($res) $this->redirect($_SERVER['HTTP_REFERER']);
		$this->error("操作失败");
	}
	
}